package com.kitbox.hl.meshow.common.utils.upload;



import java.io.IOException;
import java.io.InputStream;

/**
 * 文件上传工具类
 *
 * @author caozj
 *
 */
public class UploadUtilProxy implements UploadUtil{

	private String storage;

	private UploadUtil upload;

	public UploadUtil getUpload() {
		return upload;
	}

	private UploadUtilProxy() {
		init();
	}

	private void init() {
	//	storage = ApplicationContextUtil.getBean(EnvironmentUtil.class).get("files.storage");
		if (storage==null||"".equals(storage)){
			//upload = LocalUpload.getInstance();
		}
		else if ("local".equals(storage)) {
			//upload = LocalUpload.getInstance();
		} else if ("fastdfs".equals(storage)) {
			//upload = FastdfsUpload.getInstance();
		} else if ("alioss".equals(storage)) {
			//upload = AliOssUpload.getInstance();
		}
	}




	@Override
	public String upload(byte[] content, String fileName, String type) throws IOException, Exception {
		return upload.upload(content,fileName,type);
	}

	@Override
	public String upload(byte[] content, String fileName) throws IOException, Exception {
		return upload.upload(content,fileName);
	}

	@Override
	public InputStream download(String fileName) throws IOException, Exception {
		return upload.download(fileName);
	}

	@Override
	public void delete(String fileName) throws IOException, Exception {
		 upload.delete(fileName);
	}

	@Override
	public long size(String fileName) throws IOException, Exception {
		return upload.size(fileName);
	}

	private static final class UploadUtilHolder {
		private static final UploadUtilProxy instance = new UploadUtilProxy();
	}

	public static UploadUtilProxy getInstance() {
		return UploadUtilHolder.instance;
	}

}
